Package gri.tasks.gui

Source Code of gri.tasks.gui.DefaultStyles

/*
* File: DefaultStyles.java
* Author: Daniel Rogers
* Created on Apr 11, 2008
*
*/
package gri.tasks.gui;

import java.awt.*;

import javax.swing.*;

import dan.swing.JPrettyButton;
import dan.swing.painters.GradientPainter;
import dan.swing.style.Stylizer;
import dan.swing.style.AppStyles;

import java.util.Map;
import java.util.HashMap;

public class DefaultStyles implements Stylizer {

  Map media = new HashMap();

  public static void load() {
    AppStyles.getInstance().add(new DefaultStyles());
  }

  public void style(Component comp, String s) {

    // -------------------------------------------- Job Status

    if (s.equals(".job-status button.view"))
      ((JPrettyButton)comp).setBackground(Color.GREEN);

    else if (s.equals(".job-status button.remove"))
      ((JPrettyButton)comp).setBackground(Color.ORANGE);

    //else if (s.equals("panel.status button.clean"))
    //    ((JPrettyButton)comp).setForeground(Color.RED);

    else if (s.equals("panel.status")) {
      JPanel pnl = (JPanel)comp;
      pnl.setBorder(BorderFactory.createCompoundBorder(
          BorderFactory.createLoweredBevelBorder(),
          BorderFactory.createEmptyBorder(5,5,5,5)
      ));
    }

    else if (s.equals("panel.job-status")) {
      JPanel pnl = (JPanel)comp;
      //pnl.setBorder(BorderFactory.createLineBorder(Color.BLACK));
      pnl.setBorder(BorderFactory.createCompoundBorder(
          BorderFactory.createEtchedBorder(),
          BorderFactory.createEmptyBorder(5,5,5,5)
      ));
    }

    else if (s.equals(".job-status label.icon .running")) {
      JLabel lblIcon = (JLabel)comp;
      Image img = getImage("image.job-running", "images/job_running.png");
      lblIcon.setIcon(new ImageIcon(img));
    }
    else if (s.equals(".job-status label.icon .complete")) {
      JLabel lblIcon = (JLabel)comp;
      Image img = getImage("image.job-complete", "images/job_complete.png");
      lblIcon.setIcon(new ImageIcon(img));
    }

    // ------------------------------------ Task Header

    else if (s.equals("TaskHeaderPanel")) {
      TaskHeaderPanel pnl = (TaskHeaderPanel)comp;
      pnl.setBorder(BorderFactory.createCompoundBorder(
          //new LineBorder(Color.BLACK, 2, true),
          BorderFactory.createEtchedBorder(),
          BorderFactory.createEmptyBorder(5,5,5,5)
      ));

      GradientPainter p = new GradientPainter();
      p.setDirection(GradientPainter.TOP_LEFT_DIAGONAL);
      pnl.setComponentPainter(p);

      //pnl.setBackground(Color.GRAY.brighter());
      //pnl.setOpaque(true);

      Image img = getImage("images/document_new_lined_48.png");
      pnl.setIcon(new ImageIcon(img));
    }

    // ------------------------------------------ ParameterPanel

    else if (s.equals("ParameterPanel")) {
      ParameterPanel pnl = (ParameterPanel)comp;
      pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    }
    else if (s.equals("ParameterPanel button.run")) {
      ((JPrettyButton)comp).setBackground(Color.GREEN);
    }
    else if (s.equals("ParameterPanel.ParamPanel")) {
      ParameterPanel.ParamPanel pnl = (ParameterPanel.ParamPanel)comp;

      pnl.setBorder(BorderFactory.createCompoundBorder(
          BorderFactory.createEmptyBorder(0,0,4,0),
          BorderFactory.createCompoundBorder(
              BorderFactory.createEtchedBorder(),
              BorderFactory.createEmptyBorder(3,3,3,3)
          )
      ));


    }
    else if (s.equals("ParameterPanel.ParamPanel label.name")) {
      JLabel lbl = (JLabel)comp;
      Font oldFont = lbl.getFont();
      lbl.setFont(oldFont.deriveFont(Font.BOLD));
      //                 .deriveFont(oldFont.getSize() * 1.2f)
      //          );
    }
    else if (s.equals("ParameterPanel.ParamPanel label.help")) {
      JLabel lbl = (JLabel)comp;
      lbl.setFont(lbl.getFont().deriveFont(Font.ITALIC));

      lbl.setBorder(BorderFactory.createEmptyBorder(6,0,0,0));
    }

  }

  /**
   * Loads an image.  An ID is given for the image so that we need only
   * load it once.  It will be cached in a map for easy retrieval.
   *
   * @param id - The unique identifier for this image
   * @param path - The path to the image file to load (used first time)
   */
  protected Image getImage(String id, String path) {
    Image img = (Image)media.get(id);
    if (img == null) {
      img = Toolkit.getDefaultToolkit().getImage(path);
      media.put(id, img);
    }
    return img;
  }
  protected Image getImage(String path) {
    return getImage(path, path);
  }

}
TOP

Related Classes of gri.tasks.gui.DefaultStyles

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.